import { Image } from '@react-pdf/renderer';
import QRCode from 'qrcode';
export interface PdfQRCodeProps {
    src?: string;
    value?: string;
    style?: React.CSSProperties;
}
export const PdfQRCode = (props: PdfQRCodeProps) => {
    return <>{props.src && <Image  {...props} style={{ ...props.style }} />}</>
}
PdfQRCode.loadData = async (nodes: any[]) => {
    for (const node of nodes) {
        if (node.type == 'PdfQRCode') {
            const width = node.width;
            const code = await QRCode.toDataURL(node.data.value ?? "wwww.baidu.com/", {
                width: width,
                margin: 1,
                color: {
                    dark: node.data.style?.color ?? "#52c41a",// data.fgColor,
                    light: node.data.style?.backgroundColor ?? "#f5f5f5"//bgColor
                }
            })
            node.data.src = code;
        }
    }
    return nodes;
}
